package com.settlement.system.converter;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.apache.commons.lang3.StringUtils;

/**
 * @author author
 */
public class UnificationConvertVoucherType extends StringStringConverter {

    @Override
    public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        final String chineseComma = "，";
        final String englishComma = ",";
        final String backSlash = "/";

        boolean flag = StringUtils.isNotBlank(value)
                && (value.contains(englishComma) || value.contains(chineseComma));
        if(flag){
            return new WriteCellData(value.replace(englishComma,backSlash).replace(chineseComma,backSlash));
        }
        return super.convertToExcelData(value, contentProperty, globalConfiguration);
    }
}
